//
//  TravelAreaTourTableViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelAreaTourTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>


@interface TravelAreaTourTableViewCell ()

@property (nonatomic, retain) UIImageView *imagePic;

@property (nonatomic, retain) UILabel *labelName;

@property (nonatomic, retain) UILabel *labelDes;

@property (nonatomic, retain) UILabel *labelCount;


@end


@implementation TravelAreaTourTableViewCell

-(void)dealloc
{
    [_imagePic release];
    [_labelCount release];
    [_labelDes release];
    [_labelName release];
    [_model release];
    [super dealloc];
    
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

-(void)createView
{
    self.imagePic = [[UIImageView alloc]init];
    
    [self addSubview:self.imagePic];
    [_imagePic release];
    
    
    self.labelCount = [[UILabel alloc]init];
    self.labelCount.font = [UIFont systemFontOfSize:14 *kWidth];
    self.labelCount.textAlignment = NSTextAlignmentCenter;
    
    self.labelCount.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
    
    self.labelCount.textColor = [UIColor whiteColor];
    [self.imagePic addSubview:self.labelCount];
    [_labelCount release];
    
    
    self.labelName = [[UILabel alloc]init];
    
    self.labelName.font = [UIFont systemFontOfSize:17 *kWidth];
    
    [self addSubview:self.labelName];
    [_labelName release];
    
    self.labelDes = [[UILabel alloc]init];
    self.labelDes.font = [UIFont systemFontOfSize:14 *kWidth];
    
    self.labelDes.textColor =[UIColor lightGrayColor];
    self.labelDes.numberOfLines = 0;
    
    [self addSubview:self.labelDes];
    [_labelDes release];
    
    
    
    
    
}

-(void)setModel:(TravelTourModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    
    [self.imagePic sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"Travel_place"]];
    self.labelCount.text =  [NSString stringWithFormat:@"%@游篇记",model.attraction_trips_count];
    
    self.labelDes.text = model.description_summary;
    self.labelName.text = model.name;

    
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imagePic.frame = CGRectMake(5 *kWidth, 5 *kWidth, (self.frame.size.width - 10*kWidth ) / 3, self.frame.size.height - 10 *kHeight);
    
    self.labelCount.frame = CGRectMake(0, self.imagePic.frame.size.height / 4 * 3, self.imagePic.frame.size.width, self.imagePic.frame.size.height / 4);
    
    self.labelName.frame  = CGRectMake(self.imagePic.frame.origin.x +self.imagePic.frame.size.width + 5 *kWidth, self.imagePic.frame.origin.y, self.frame.size.width - self.imagePic.frame.size.width, 30 *kHeight);
    
    self.labelDes.frame = CGRectMake(self.labelName.frame.origin.x, self.labelName.frame.size.height + self.labelName.frame.origin.y + 15 *kHeight , self.labelName.frame.size.width - 10 *kWidth, self.frame.size.height - self.labelName.frame.size.height - self.labelName.frame.origin.y - 30 *kHeight);
  
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
